package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.AccessBean;
import com.lc.pianostudent.bean.GetStudyPictureBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.MAIL_GETSTUDY)
public class PostMailGetstudy extends BaseAsyPost {

    public String id,type;
    public PostMailGetstudy(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostMailGetstudyInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostMailGetstudyInfo info = new PostMailGetstudyInfo();

            info.code = object.optString("code");
            JSONObject jsonObject = object.optJSONObject("data");

            if(jsonObject != null){
                info.cname = jsonObject.optString("cname");
                info.name = jsonObject.optString("name");
                info.person = jsonObject.optString("person");
                info.wealth = jsonObject.optString("wealth");
                info.degree = jsonObject.optString("degree");
                info.xuewei = jsonObject.optString("xuewei");
                info.grade = jsonObject.optString("grade");
                info.exper = jsonObject.optString("exper");
                info.num = jsonObject.optString("num");
            }


            JSONArray array = object.optJSONArray("list");

            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);

                    GetStudyPictureBean getStudyPictureBean = new GetStudyPictureBean();
                    getStudyPictureBean.setContent(o.optString("content"));
                    getStudyPictureBean.setCreate_time(o.optString("create_time"));
                    getStudyPictureBean.setDay(o.optString("day"));
                    getStudyPictureBean.setMouse(o.optString("mouse"));
                    getStudyPictureBean.setPicarr(o.optString("picarr"));
                    getStudyPictureBean.setUserid(o.optString("userid"));
                    getStudyPictureBean.setId(o.optString("id"));
                    info.contactDetailList.add(getStudyPictureBean);
                }
            }

            JSONObject hair = object.optJSONObject("hair");
            info.hair_id = hair.optString("id");
            info.hair_type = hair.optString("type");
            info.hair_picurl = hair.optString("picurl");

            JSONObject jack = object.optJSONObject("jack");
            info.jack_id = jack.optString("id");
            info.jack_type = jack.optString("type");
            info.jack_picurl = jack.optString("picurl");

            JSONObject download = object.optJSONObject("download");
            info.download_id = download.optString("id");
            info.download_type = download.optString("type");
            info.download_picurl = download.optString("picurl");

            JSONObject shose = object.optJSONObject("shose");
            info.shose_id = shose.optString("id");
            info.shose_type = shose.optString("type");
            info.shose_picurl = shose.optString("picurl");

            JSONObject suit = object.optJSONObject("suit");
            info.suit_id = suit.optString("id");
            info.suit_type = suit.optString("type");
            info.suit_picurl = suit.optString("picurl");

            JSONObject expression = object.optJSONObject("expression");
            info.expression_id = expression.optString("id");
            info.expression_type = expression.optString("type");
            info.expression_picurl = expression.optString("picurl");

            JSONArray access = object.optJSONArray("access");
            if(access != null || access.length() != 0){
                for(int i = 0;i<access.length();i++){
                    JSONObject o = access.optJSONObject(i);
                    AccessBean accessBean = new AccessBean();
                    accessBean.setId(o.optString("id"));
                    accessBean.setPicurl(o.optString("picurl"));
                    accessBean.setType(o.optString("type"));
                    info.accessShowList.add(accessBean);

                }
            }
            info.mote = object.optString("mote");
            info.data = object.optString("data");
            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostMailGetstudyInfo {

        public String code,cname,name,person,wealth,degree,xuewei,grade,exper,num,
        hair_id,hair_type,hair_picurl,jack_id,jack_type,jack_picurl,
        download_id,download_type,download_picurl,shose_id,shose_type,shose_picurl
                ,suit_id,suit_type,suit_picurl,expression_id,expression_type,expression_picurl,mote,data;

        public ArrayList<GetStudyPictureBean> contactDetailList = new ArrayList<>();
        public List<AccessBean> accessShowList = new ArrayList<>();
    }

}
